package qqclient.view;

import qqclient.service.UserClientService;
import qqclient.utils.Utility;

/**
 * @author DCSGO
 * @version 1.0
 * 客户端的菜单界面
 */
public class QQView {
    private boolean loop = true;

    public static void main(String[] args) {
        new QQView().mainMenu();
        System.out.println("已退出程序...");
    }

    private void mainMenu() {
        String key;//用户键盘输入

        while (loop) {//一级菜单
            System.out.println("=====欢迎登录网络通行系统=====");
            System.out.println("\t\t1 登录系统");
            System.out.println("\t\t9 退出系统");
            System.out.print("请输入你的选择：");
            key = Utility.readString(1);

            switch (key) {
                case "1":
                    //登录系统相关操作
                    System.out.print("请输入用户名：");
                    String id = Utility.readString(50);
                    System.out.print("请输入密  码：");
                    String pwd = Utility.readString(50);
                    UserClientService userClientService = new UserClientService();

                    //服务端验证该用户是否存在
                    if (userClientService.checkUser(id, pwd)) {//登录成功
                        System.out.println("欢迎 " + id);
                        while (loop) {//登录成功二级菜单
                            System.out.println("===网络通信系统二级菜单(用户 " + id + " )===");
                            System.out.println("\t\t1 显示在线用户列表");
                            System.out.println("\t\t2 群发消息");
                            System.out.println("\t\t3 私聊消息");
                            System.out.println("\t\t4 发送文件");
                            System.out.println("\t\t9 退出系统");
                            System.out.print("请输入你的选择：");
                            key = Utility.readString(1);
                            switch (key) {
                                case "1":
                                    //显示在线用户列表
                                    userClientService.printOnlineUsers();
                                    break;
                                case "2":
                                    //广播消息
                                    userClientService.sendMessagesToAll();
                                    break;
                                case "3":
                                    userClientService.sendMessage();
                                    break;
                                case "4":
                                    //发送文件
                                    userClientService.sendFile();
                                    break;
                                case "9":
                                    //退出系统
                                    userClientService.exit();
                                    loop = false;
                                    break;
                                default:
                                    System.out.println("暂无该选项！");
                                    break;
                            }
                        }
                    } else {//登录失败
                        System.out.println("登录失败！");
                    }
                    break;

                case "9":
                    //退出系统相关操作
                    loop = false;
                    break;

                default:
                    System.out.println("暂无该选项！");
                    break;
            }
        }
    }

}
